package com.moyun.finance.controller;

import com.moyun.finance.entity.Contract;
import com.moyun.finance.entity.Customer;
import com.moyun.finance.entity.Product;
import com.moyun.finance.entity.Response;
import com.moyun.finance.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    CustomerService cs;

    //客户新增
    @RequestMapping("/save")
    public @ResponseBody Response save(@RequestBody Customer customer){
        Response res = cs.save(customer);
        return res;
    }

    //客户修改
    @RequestMapping("/update")
    public @ResponseBody Response update(@RequestBody Customer customer){
        Response res = cs.update(customer);
        return res;
    }

    //客户删除
    @RequestMapping("/delete")
    public @ResponseBody Response delete(@RequestBody Customer customer){
        Response res = cs.delete(customer);
        return res;
    }

    //查询指定公司所有客户信息
    @RequestMapping("/findAllByCompanyId")
    public @ResponseBody Response findAllByDeptId(String companyId){
        List<Customer> customers = cs.findAll(companyId);
        return new Response("",customers,true);
    }

    //根据id查客户
    @RequestMapping("/findById")
    public @ResponseBody Response findOneById(String customerId){
        Customer cus = cs.findOneById(customerId);
        return new Response("",cus,true);
    }

    //根据公司和客户名字模糊查询
    @RequestMapping("/findByNameLike")
    public @ResponseBody Response findByNameLike(String companyId, String customerName){
        List<Customer> cus = cs.findByNameLike(companyId, customerName);
        return new Response("",cus,true);
    }

    //根据子菜单查本公司下所有
    @RequestMapping("/findByAllType")
    public @ResponseBody Response findByAllType(String companyId, String allTypeId, String customerType){
        List<Customer> customers = cs.findByAllType(companyId, allTypeId, customerType);
        return new Response("",customers,true);
    }
}
